using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
using WPFExcelReport.Helpers;
using WPFExcelReport.Controls;
namespace WPFExcelReport
{
    public partial class VQVW_EKPOS
    {
        public DataRow Convert2QVW_EKPOS(DataRow dwInput, string ITXDBVERSION, bool IsConvert = false)
        {
            DataSet SResult = new DataSet();
            SResult = QueryQVW_EKPOS(dwInput, 0);
            DataRow dwReturn = null;
            if (SResult.Tables[0].Rows.Count > 0)
            {
                dwReturn = SResult.Tables[0].Rows[0];
            }
            else
            {
                dwReturn = SResult.Tables[0].NewRow();
            }
            switch (ITXDBVERSION)
            {
                case "YGR":
                    #region=========
         dwReturn["NDATE"] = " ".PadRight(0 ); 
         dwReturn["NYEAR"] = " ".PadRight(4 ); 
         dwReturn["NMONTH"] = " ".PadRight(2 ); 
         dwReturn["NDAY"] = " ".PadRight(2 ); 
         dwReturn["NQUARTER"] = " ".PadRight(41 ); 
         dwReturn["KAUF"] = " ".PadRight(9 ); 
         dwReturn["AUFTYP"] = " ".PadRight(1 ); 
         dwReturn["PAUF"] = " ".PadRight(12 ); 
         dwReturn["PKRS"] = " ".PadRight(2 ); 
         dwReturn["PLFD"] = " ".PadRight(6 ); 
         dwReturn["PPOS"] = " ".PadRight(3 ); 
         dwReturn["LSNR"] = " ".PadRight(8 ); 
         dwReturn["KSTAFF"] = " ".PadRight(8 ); 
         dwReturn["EKPPOSTYP"] = " ".PadRight(3 ); 
         dwReturn["ARTST"] = " ".PadRight(1 ); 
         dwReturn["PART"] = " ".PadRight(4000 ); 
         dwReturn["PVAR"] = " ".PadRight(4000 ); 
         dwReturn["PCOLOR"] = " ".PadRight(4000 ); 
         dwReturn["PDESS"] = " ".PadRight(10 ); 
         dwReturn["PDCWY"] = " ".PadRight(10 ); 
         dwReturn["PFINISH"] = " ".PadRight(10 ); 
         dwReturn["PSIZE"] = " ".PadRight(7 ); 
         dwReturn["EKPMEEH"] = " ".PadRight(3 ); 
         dwReturn["EKPPRME"] = " ".PadRight(10 ); 
         dwReturn["EKPPREH"] = " ".PadRight(3 ); 
         dwReturn["EKPPREHFKT"] = " ".PadRight(12 ); 
         dwReturn["EKPME1"] = " ".PadRight(0 ); 
         dwReturn["EKPWE1"] = " ".PadRight(0 ); 
         dwReturn["EKPME3"] = " ".PadRight(0 ); 
         dwReturn["EKPWE3"] = " ".PadRight(0 ); 
         dwReturn["EKPPREIS"] = " ".PadRight(0 ); 
         dwReturn["EKPVALUE"] = " ".PadRight(0 ); 
         dwReturn["EKPQTY"] = " ".PadRight(0 ); 
         dwReturn["QRECEIVE"] = " ".PadRight(0 ); 
         dwReturn["DDAT"] = " ".PadRight(0 ); 
         dwReturn["DYEAR"] = " ".PadRight(4 ); 
         dwReturn["DMONTH"] = " ".PadRight(2 ); 
         dwReturn["DDAY"] = " ".PadRight(2 ); 
         dwReturn["DQUARTER"] = " ".PadRight(41 ); 
         dwReturn["DRDAT"] = " ".PadRight(0 ); 
         dwReturn["DRYEAR"] = " ".PadRight(4 ); 
         dwReturn["DRMONTH"] = " ".PadRight(2 ); 
         dwReturn["DRDAY"] = " ".PadRight(2 ); 
         dwReturn["DRQUARTER"] = " ".PadRight(41 ); 
         dwReturn["VTERMDAT"] = " ".PadRight(0 ); 
         dwReturn["VYEAR"] = " ".PadRight(4 ); 
         dwReturn["VMONTH"] = " ".PadRight(2 ); 
         dwReturn["VDAY"] = " ".PadRight(2 ); 
         dwReturn["UTERMDAT"] = " ".PadRight(0 ); 
         dwReturn["UYEAR"] = " ".PadRight(4 ); 
         dwReturn["UMONTH"] = " ".PadRight(2 ); 
         dwReturn["UDAY"] = " ".PadRight(2 ); 
         dwReturn["RDATE"] = " ".PadRight(0 ); 
         dwReturn["RYEAR"] = " ".PadRight(4 ); 
         dwReturn["RMONTH"] = " ".PadRight(2 ); 
         dwReturn["RDAY"] = " ".PadRight(2 ); 
         dwReturn["EKOTD"] = " ".PadRight(1 ); 
                    #endregion
                    break;
                case "JLT":

                    break;
                default:

                    break;
            }
            if (IsConvert)
            {
                foreach (DataColumn cm in dwInput.Table.Columns)
                {
                    if (dwInput[cm.ColumnName].ToString() == "")
                        continue;
                    if (dwReturn.Table.Columns.Contains(cm.ColumnName))
                    {
                        dwReturn[cm.ColumnName] = dwInput[cm.ColumnName];
                    }
                }
            }
            return dwReturn;
        }
        public void MapQVW_EKPOS(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveQVW_EKPOS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet setResult = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            setResult = QueryQVW_EKPOS(dwData);
            if (setResult.Tables.Count > 0)
            {
                tbLocal = setResult.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            MapQVW_EKPOS(ref dwLocal, dwData);

            if (!flgExist)
            {

                InsertQVW_EKPOS(dwLocal, ITXDBVERSION);
            }
            UpdateQVW_EKPOS(dwLocal);
        }
        public void InsertQVW_EKPOS(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            or1 = OracleDB.CreateCommand();
            switch (ITXDBVERSION)
            {
                case "YGR":
                    or1.CommandText = "INSERT INTO QVW_EKPOS(VAKBMANDANT, VAKBKOLL, VAKBART, VAKBKUNDNR, VAKBFARBE, VAKBKDARTNR, VAKBKDARTBEZ, VAKBKDFARBNR, VAKBANDRUCK, VAKBMEGEW, VAKBMENGEH, VAKBGEWVON, VAKBGEWBIS, VAKBGEWCA, VAKBGEWFKT, VAKBGEWGRP, VAKBMEGFKT, VAKBMEGGRP, VAKBAENDZL, VAKBAENDBEN, VAKBAENDDAT, VAKBNEUBEN, VAKBNEUDAT, VAKBFILLER)"
                        + " VALUES (:VAKBMANDANT, :VAKBKOLL, :VAKBART, :VAKBKUNDNR, :VAKBFARBE, '                         ', '                         ', '                             ', ' ', '   ', '   ', 0, 0, ' ', '000000000000', ' ', '000000000000', ' ', 0, '        ', '000000', '        ', '      ', '                                          ')";
                    or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                //VAFMANDANT VAFKOLL VAFART VAFFARBE VAFBEZ VAFFFARBE

            }
            
            Connect2Proxy(or1);
        }
        public DataSet QueryQVW_EKPOS(DataRow dwData, int option = 1)
        {
            DataSet Return;
            DataSet Result = new DataSet();
            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 0:
                    or1.CommandText = "SELECT * FROM QVW_EKPOS WHERE  ROWNUM<2 ";
                    break;
              
                case 99:
                    or1.CommandText = "SELECT * FROM QVW_EKPOS  WHERE ROWNUM<50";
                    break;
                default:
                    break;
            }
            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
                Result.Tables[0].TableName = "QVW_EKPOS";
            Return = Result;
            return Return;
        }
        public void DeleteQVW_EKPOS(DataRow dwData, int option = 1)
        {

            OracleCommand or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    or1.CommandText = "DELETE FROM QVW_EKPOS   WHERE  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                     or1.Parameters.Add("VAKBMANDANT", OracleType.NVarChar).Value = dwData["VAKBMANDANT"].ToString();
                    or1.Parameters.Add("VAKBKOLL", OracleType.NVarChar).Value = dwData["VAKBKOLL"].ToString();
                    or1.Parameters.Add("VAKBART", OracleType.NVarChar).Value = dwData["VAKBART"].ToString();
                    or1.Parameters.Add("VAKBFARBE", OracleType.NVarChar).Value = dwData["VAKBFARBE"].ToString();
                    or1.Parameters.Add("VAKBKUNDNR", OracleType.NVarChar).Value = dwData["VAKBKUNDNR"].ToString();
                    break;
                default:
                    break;
            }
            Connect2Proxy(or1);
        } 
      
        public void UpdateQVW_EKPOS(DataRow dwData, string ITXDBVERSION = "50.24", int option = 1)
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();
            switch (option)
            {
                case 1:
                    #region====Command==== 
                    or1.CommandText = "UPDATE QVW_EKPOS SET "
                    +"NDATE= :NDATE,"
                    +"NYEAR= :NYEAR,"
                    +"NMONTH= :NMONTH,"
                    +"NDAY= :NDAY,"
                    +"NQUARTER= :NQUARTER,"
                    +"KAUF= :KAUF,"
                    +"AUFTYP= :AUFTYP,"
                    +"PAUF= :PAUF,"
                    +"PKRS= :PKRS,"
                    +"PLFD= :PLFD,"
                    +"PPOS= :PPOS,"
                    +"LSNR= :LSNR,"
                    +"KSTAFF= :KSTAFF,"
                    +"EKPPOSTYP= :EKPPOSTYP,"
                    +"ARTST= :ARTST,"
                    +"PART= :PART,"
                    +"PVAR= :PVAR,"
                    +"PCOLOR= :PCOLOR,"
                    +"PDESS= :PDESS,"
                    +"PDCWY= :PDCWY,"
                    +"PFINISH= :PFINISH,"
                    +"PSIZE= :PSIZE,"
                    +"EKPMEEH= :EKPMEEH,"
                    +"EKPPRME= :EKPPRME,"
                    +"EKPPREH= :EKPPREH,"
                    +"EKPPREHFKT= :EKPPREHFKT,"
                    +"EKPME1= :EKPME1,"
                    +"EKPWE1= :EKPWE1,"
                    +"EKPME3= :EKPME3,"
                    +"EKPWE3= :EKPWE3,"
                    +"EKPPREIS= :EKPPREIS,"
                    +"EKPVALUE= :EKPVALUE,"
                    +"EKPQTY= :EKPQTY,"
                    +"QRECEIVE= :QRECEIVE,"
                    +"DDAT= :DDAT,"
                    +"DYEAR= :DYEAR,"
                    +"DMONTH= :DMONTH,"
                    +"DDAY= :DDAY,"
                    +"DQUARTER= :DQUARTER,"
                    +"DRDAT= :DRDAT,"
                    +"DRYEAR= :DRYEAR,"
                    +"DRMONTH= :DRMONTH,"
                    +"DRDAY= :DRDAY,"
                    +"DRQUARTER= :DRQUARTER,"
                    +"VTERMDAT= :VTERMDAT,"
                    +"VYEAR= :VYEAR,"
                    +"VMONTH= :VMONTH,"
                    +"VDAY= :VDAY,"
                    +"UTERMDAT= :UTERMDAT,"
                    +"UYEAR= :UYEAR,"
                    +"UMONTH= :UMONTH,"
                    +"UDAY= :UDAY,"
                    +"RDATE= :RDATE,"
                    +"RYEAR= :RYEAR,"
                    +"RMONTH= :RMONTH,"
                    +"RDAY= :RDAY,"
                    +"EKOTD= :EKOTD,"
                        + " WHERE  "
                        + "  VAKBMANDANT=:VAKBMANDANT AND VAKBKOLL=:VAKBKOLL AND VAKBART =:VAKBART AND VAKBFARBE=:VAKBFARBE AND VAKBKUNDNR=:VAKBKUNDNR";
                    #endregion

                    #region====Parameters====
          or1.Parameters.Add("NDATE", OracleType.NVarChar).Value = dwData["NDATE"].ToString(); 
          or1.Parameters.Add("NYEAR", OracleType.NVarChar).Value = dwData["NYEAR"].ToString(); 
          or1.Parameters.Add("NMONTH", OracleType.NVarChar).Value = dwData["NMONTH"].ToString(); 
          or1.Parameters.Add("NDAY", OracleType.NVarChar).Value = dwData["NDAY"].ToString(); 
          or1.Parameters.Add("NQUARTER", OracleType.NVarChar).Value = dwData["NQUARTER"].ToString(); 
          or1.Parameters.Add("KAUF", OracleType.NVarChar).Value = dwData["KAUF"].ToString(); 
          or1.Parameters.Add("AUFTYP", OracleType.NVarChar).Value = dwData["AUFTYP"].ToString(); 
          or1.Parameters.Add("PAUF", OracleType.NVarChar).Value = dwData["PAUF"].ToString(); 
          or1.Parameters.Add("PKRS", OracleType.NVarChar).Value = dwData["PKRS"].ToString(); 
          or1.Parameters.Add("PLFD", OracleType.NVarChar).Value = dwData["PLFD"].ToString(); 
          or1.Parameters.Add("PPOS", OracleType.NVarChar).Value = dwData["PPOS"].ToString(); 
          or1.Parameters.Add("LSNR", OracleType.NVarChar).Value = dwData["LSNR"].ToString(); 
          or1.Parameters.Add("KSTAFF", OracleType.NVarChar).Value = dwData["KSTAFF"].ToString(); 
          or1.Parameters.Add("EKPPOSTYP", OracleType.NVarChar).Value = dwData["EKPPOSTYP"].ToString(); 
          or1.Parameters.Add("ARTST", OracleType.NVarChar).Value = dwData["ARTST"].ToString(); 
          or1.Parameters.Add("PART", OracleType.NVarChar).Value = dwData["PART"].ToString(); 
          or1.Parameters.Add("PVAR", OracleType.NVarChar).Value = dwData["PVAR"].ToString(); 
          or1.Parameters.Add("PCOLOR", OracleType.NVarChar).Value = dwData["PCOLOR"].ToString(); 
          or1.Parameters.Add("PDESS", OracleType.NVarChar).Value = dwData["PDESS"].ToString(); 
          or1.Parameters.Add("PDCWY", OracleType.NVarChar).Value = dwData["PDCWY"].ToString(); 
          or1.Parameters.Add("PFINISH", OracleType.NVarChar).Value = dwData["PFINISH"].ToString(); 
          or1.Parameters.Add("PSIZE", OracleType.NVarChar).Value = dwData["PSIZE"].ToString(); 
          or1.Parameters.Add("EKPMEEH", OracleType.NVarChar).Value = dwData["EKPMEEH"].ToString(); 
          or1.Parameters.Add("EKPPRME", OracleType.NVarChar).Value = dwData["EKPPRME"].ToString(); 
          or1.Parameters.Add("EKPPREH", OracleType.NVarChar).Value = dwData["EKPPREH"].ToString(); 
          or1.Parameters.Add("EKPPREHFKT", OracleType.NVarChar).Value = dwData["EKPPREHFKT"].ToString(); 
          or1.Parameters.Add("EKPME1", OracleType.NVarChar).Value = dwData["EKPME1"].ToString(); 
          or1.Parameters.Add("EKPWE1", OracleType.NVarChar).Value = dwData["EKPWE1"].ToString(); 
          or1.Parameters.Add("EKPME3", OracleType.NVarChar).Value = dwData["EKPME3"].ToString(); 
          or1.Parameters.Add("EKPWE3", OracleType.NVarChar).Value = dwData["EKPWE3"].ToString(); 
          or1.Parameters.Add("EKPPREIS", OracleType.NVarChar).Value = dwData["EKPPREIS"].ToString(); 
          or1.Parameters.Add("EKPVALUE", OracleType.NVarChar).Value = dwData["EKPVALUE"].ToString(); 
          or1.Parameters.Add("EKPQTY", OracleType.NVarChar).Value = dwData["EKPQTY"].ToString(); 
          or1.Parameters.Add("QRECEIVE", OracleType.NVarChar).Value = dwData["QRECEIVE"].ToString(); 
          or1.Parameters.Add("DDAT", OracleType.NVarChar).Value = dwData["DDAT"].ToString(); 
          or1.Parameters.Add("DYEAR", OracleType.NVarChar).Value = dwData["DYEAR"].ToString(); 
          or1.Parameters.Add("DMONTH", OracleType.NVarChar).Value = dwData["DMONTH"].ToString(); 
          or1.Parameters.Add("DDAY", OracleType.NVarChar).Value = dwData["DDAY"].ToString(); 
          or1.Parameters.Add("DQUARTER", OracleType.NVarChar).Value = dwData["DQUARTER"].ToString(); 
          or1.Parameters.Add("DRDAT", OracleType.NVarChar).Value = dwData["DRDAT"].ToString(); 
          or1.Parameters.Add("DRYEAR", OracleType.NVarChar).Value = dwData["DRYEAR"].ToString(); 
          or1.Parameters.Add("DRMONTH", OracleType.NVarChar).Value = dwData["DRMONTH"].ToString(); 
          or1.Parameters.Add("DRDAY", OracleType.NVarChar).Value = dwData["DRDAY"].ToString(); 
          or1.Parameters.Add("DRQUARTER", OracleType.NVarChar).Value = dwData["DRQUARTER"].ToString(); 
          or1.Parameters.Add("VTERMDAT", OracleType.NVarChar).Value = dwData["VTERMDAT"].ToString(); 
          or1.Parameters.Add("VYEAR", OracleType.NVarChar).Value = dwData["VYEAR"].ToString(); 
          or1.Parameters.Add("VMONTH", OracleType.NVarChar).Value = dwData["VMONTH"].ToString(); 
          or1.Parameters.Add("VDAY", OracleType.NVarChar).Value = dwData["VDAY"].ToString(); 
          or1.Parameters.Add("UTERMDAT", OracleType.NVarChar).Value = dwData["UTERMDAT"].ToString(); 
          or1.Parameters.Add("UYEAR", OracleType.NVarChar).Value = dwData["UYEAR"].ToString(); 
          or1.Parameters.Add("UMONTH", OracleType.NVarChar).Value = dwData["UMONTH"].ToString(); 
          or1.Parameters.Add("UDAY", OracleType.NVarChar).Value = dwData["UDAY"].ToString(); 
          or1.Parameters.Add("RDATE", OracleType.NVarChar).Value = dwData["RDATE"].ToString(); 
          or1.Parameters.Add("RYEAR", OracleType.NVarChar).Value = dwData["RYEAR"].ToString(); 
          or1.Parameters.Add("RMONTH", OracleType.NVarChar).Value = dwData["RMONTH"].ToString(); 
          or1.Parameters.Add("RDAY", OracleType.NVarChar).Value = dwData["RDAY"].ToString(); 
          or1.Parameters.Add("EKOTD", OracleType.NVarChar).Value = dwData["EKOTD"].ToString(); 
                    #endregion
                    break; 
                default:
                    break;
            }


            Connect2Proxy(or1);
        }
    }
}
